package com.gitee.wsl.text.regex.sample

/**
 * A newline including horizontal whitespace that follows, allowing us to get the indentation
 * level from the matched content.
 */
val Regex.Companion.NEWLINE: Regex
    get() = Regex("""\n[ \t]*""")

/** At least one whitespace character */
val Regex.Companion.WHITESPACE: Regex
    get() = Regex("""\s+""")

/** Horizontal whitespace, i.e. whitespace excluding newline characters. */
val Regex.Companion.HORIZONTAL_WHITESPACE: Regex
    get() = Regex("""[ \t]+""")

/** At least one letter, '_' or '$', followed by any number of the same or digits. */
val Regex.Companion.IDENTIFIER: Regex
    get() = Regex("""[\p{Alpha}_$][\p{Alpha}_$\d]*""")

/**
 * Regex for recognizing double-quoted strings, including quotes escaped using a backslash.
 *
 * Additional forms of character escapes can be recognized (or rejected) in post-processing.
 */
val Regex.Companion.DOUBLE_QUOTED_STRING: Regex
    get() = Regex(""""([^"\\]*(\\.[^"\\]*)*)"""")

/**
 * Regex for recognizing single-quoted strings, including quotes escaped using a backslash.
 *
 * Additional forms of character escapes can be recognized (or rejected) in post-processing.
 */
val Regex.Companion.SINGLE_QUOTED_STRING: Regex
    get() = Regex("""'([^"\\]*(\\.[^'\\]*)*)'""")

/**
 * Recognizes double-quoted strings using doubled double-quotes as escape for double-quotes,
 * as used in the CSV format and BASIC interpreters.
 */
val Regex.Companion.CSV_STRING: Regex
    get() = Regex(""""([^"]*(""[^"]*)*)"""")

